package com.sea.app.module.identity;

import com.sea.app.common.Entity.http.Response;
import com.sea.app.common.kit.ServletRequests;
import com.sea.app.module.identity.domain.algorithm.JwtToken;
import com.sea.app.module.identity.domain.service.AuthService;
import com.sea.app.module.identity.transfer.AuthenticationRequest;
import com.sea.app.module.identity.transfer.AuthenticationResponse;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * Created by 31417 on 2017/4/26.
 */
@RestController
@RequestMapping("/auth")
public class AuthController {

    @Autowired
    AuthService authService;


    @RequestMapping(value = "",method = RequestMethod.POST)
    public Response.Body auth(@Valid AuthenticationRequest authParam, HttpServletRequest request){
        ServletRequests sr = ServletRequests.on(request);
        String token = authService.login(authParam.getLoginName(),authParam.getPassword(),sr.ip());
        return Response.OK.body(new AuthenticationResponse(token));
    }

    @RequestMapping(value = "/logout",method = RequestMethod.POST)
    public Response.Body logout(@RequestAttribute("loginName") String loginName,@RequestAttribute("loginUserId") String id){

        return Response.OK.body("");
    }
}
